from listnode import list_to_ln, ln_to_list


def reverse_k_group(head, k):
    head_ = ln_to_list(head)
    print(head_)
    left = c = 0
    for i in range(len(head_)):
        c += 1
        if c == k:
            head_[left: i + 1] = head_[left: i + 1][::-1]
            left = i + 1
            c = 0
    print(head_)


if __name__ == '__main__':
    sample = list_to_ln(list(range(1, 6)))
    reverse_k_group(head=sample, k=3)